package ws.search;

import cs236369.hw5.SearchWS;

public class SearchWSProxy implements cs236369.hw5.SearchWS {
	private String		_endpoint	= null;
	private SearchWS	searchWS	= null;
	
	public SearchWSProxy() {
		_initSearchWSProxy();
	}
	
	public SearchWSProxy(String endpoint) {
		_endpoint = endpoint;
		_initSearchWSProxy();
	}
	
	private void _initSearchWSProxy() {
		try {
			searchWS = (new ws.search.SearchWSServiceLocator()).getSearchWS();
			if (searchWS != null) {
				if (_endpoint != null) {
					((javax.xml.rpc.Stub)searchWS)
							._setProperty("javax.xml.rpc.service.endpoint.address", _endpoint);
				} else {
					_endpoint = (String)((javax.xml.rpc.Stub)searchWS)
							._getProperty("javax.xml.rpc.service.endpoint.address");
				}
			}
			
		} catch (javax.xml.rpc.ServiceException serviceException) {
		}
	}
	
	public String getEndpoint() {
		return _endpoint;
	}
	
	public void setEndpoint(String endpoint) {
		_endpoint = endpoint;
		if (searchWS != null) {
			((javax.xml.rpc.Stub)searchWS)._setProperty("javax.xml.rpc.service.endpoint.address", _endpoint);
		}
		
	}
	
	public SearchWS getSearchWS() {
		if (searchWS == null) {
			_initSearchWSProxy();
		}
		return searchWS;
	}
	
	@Override
	public java.lang.String[] searchLocal(double locationX, double locationY, double d)
			throws java.rmi.RemoteException {
		if (searchWS == null) {
			_initSearchWSProxy();
		}
		return searchWS.searchLocal(locationX, locationY, d);
	}
	
	@Override
	public java.lang.String[] searchKeywords(java.lang.String[] args) throws java.rmi.RemoteException {
		if (searchWS == null) {
			_initSearchWSProxy();
		}
		return searchWS.searchKeywords(args);
	}
	
}